<!--
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-07-30 20:02:30
 * @LastEditTime: 2020-02-28 11:25:38
 * @LastEditors: Please set LastEditors
 -->
<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/vant.css">
    <link rel="stylesheet" type="text/css" href="../css/base.css" />
    <script type="text/javascript" src="../script/vue.min.js"></script>
    <script type="text/javascript" src="../script/vant.min.js"></script>
    <script type="text/javascript" src="../script/base.js"></script>
    <style type="text/css">
        .content {
            display: flex;
            flex-wrap: wrap;
        }

        .van-input-div {
            width: 100%;
            display: flex;
            flex-direction: row;
        }

        .van-input {
            /* background-color: red; */
            width: 46%;
        }

        .van-input_input {
            width: 400px;
            padding: 20px;
        }

        .bottomBtn {
            width: 100%;
            margin: 10px 50px 4px 50px;
            display: flex;
            justify-content: space-between;
        }

        .van-button {
            margin: auto 10px;
            width: 100%;
        }

        .outter {
            /* width: 100px; */
            background-color: red;
            display: flex;
        }

        .fieldInner {
            width: 85%;
            /* padding: 10px; */
            margin: auto;
            border: 1px solid rgba(0, 0, 0, 0.1);
            color: #323233;
        }

        .van-radio-group {
            display: flex;
        }

        .van-radio-group .van-radio {
            flex: 1;
        }

        .Operator {
            width: 100%;
        }

        .van-tag {
            color: #0283ef;
            background: rgba(2, 131, 239, 0.1);
            margin-right: 3px;
            padding: 2px;
        }

        .van-radio_group {
            width: 82%;
            /* background-color: red; */
        }

        .top_button {
            background-color: red;
            border: 1px solid red;
            color: #fff;
        }

        .van-cell {
            width: 50%;
        }

        .van_div {
            width: 100%;
        }
    </style>
</head>

<body>
    <div id="app" v-cloak>
        <div class="box" id="box">
            <van-nav-bar :title="name + '明细'" id="safeTop" left-arrow @click-left="onClickLeft">
                <template #right v-if='CopyShow'>
                    <van-button size="small" @click='CopyAdd'>复制</van-button>
                    <van-button size="small" class="top_button" @click='Delete'>删除</van-button>
                </template>
            </van-nav-bar>
            <div class="content">
                <van-field v-model="formData.ProductName" label="产品" placeholder="请选择产品" readonly is-link
                    @click="openBaseScreen('产品')"></van-field>
                <van-field style="width: 50%; border-right: 1px solid #333" v-model="formData.OperateDate" label="操作日期"
                    placeholder="请选择操作日期" readonly is-link @click="handlerDate('操作日期')"></van-field>
                <van-field style="width: 50%;" v-model="formData.Batch" label="批次" placeholder="请填写批次"></van-field>
                <van-field style="width: 50%; border-right: 1px solid #333" v-model="formData.WorkShopName" label="车间"
                    placeholder="请选择车间" readonly is-link @click="handlerWorkShopName"></van-field>
                <div style="width: 50%;" class="van-cell van-field">
                    <div class="van-cell__title van-field__label">
                        <span>操作人</span>
                    </div>
                    <div class="Operator" @click="handlerOperator">
                        <span @click='closeTag($event,index)' class="van-tag van-tag--info"
                            v-for="(item, index) in formData.OperatorList">
                            {{ item }}
                            <i class="van-icon van-icon-clear"></i>
                        </span>
                    </div>
                </div>
                <van-field style="width: 50%; border-right: 1px solid #333" v-model="formData.CS" label="产线"
                    placeholder="请填写产线" readonly is-link @click="handlerCS">
                </van-field>
                <van-field style="width: 50%;" v-model="formData.GBCJ" label="隔板厂家" placeholder="请填写隔板厂家" readonly
                    is-link @click="handlerGBCJ">
                </van-field>
                <van-field style="width: 50%; border-right: 1px solid #333" v-model="formData.Qty" type="digit"
                    label="数量" placeholder="请填写数量"></van-field>
                <van-field style="width: 50%;" v-model="formData.TestResult" label="检验结果" placeholder="请填写检验结果" is-link
                    readonly @click="testResultShow = true"></van-field>
                <div class="van-cell van-field">
                    <div class="van-cell__title van-field__label">
                        <span>是否卡塔纳</span>
                    </div>
                    <div class="van-radio_group">
                        <van-radio-group v-model="formData.KTN">
                            <van-radio name="1">是</van-radio>
                            <van-radio name="2">否</van-radio>
                        </van-radio-group>
                    </div>
                </div>
                <div class="van_div van-cell van-field">
                    <div class="van-cell__title van-field__label">
                        <span>涂板时间</span>
                    </div>
                    <div class="van-input-div">
                        <div class=" van-input">
                            正：<input class="fieldInner" v-model="formData.up" type="text" readonly
                                @click="handlerDate('正')" />
                        </div>
                        <div class=" van-input">
                            负：<input class="fieldInner" v-model="formData.down" type="text" readonly
                                @click="handlerDate('负')" />
                        </div>
                    </div>
                </div>

                <div class="van-cell van-field">
                    <div class="van-cell__title van-field__label">
                        <span>是否内外焊</span>
                    </div>
                    <div class="van-radio_group">
                        <van-radio-group v-model="formData.NWH">
                            <van-radio name="3">空</van-radio>
                            <van-radio name="4">內焊</van-radio>
                            <van-radio name="5">外焊</van-radio>
                        </van-radio-group>
                    </div>
                </div>
                <div class="van-cell van-field">
                    <div class="van-cell__title van-field__label">
                        <span>是否电解铅</span>
                    </div>
                    <div class="van-radio_group">
                        <van-radio-group v-model="formData.IFDJQ">
                            <van-radio name="1">是</van-radio>
                            <van-radio name="2">否</van-radio>
                        </van-radio-group>
                    </div>
                </div>

                <div style="width: 100%;display: flex;">
                    <div class="van-cell van-field" style="flex: 1;">
                        <div class="van-cell__title van-field__label">
                            <span>是否送样</span>
                        </div>
                        <div class="van-radio_group">
                            <van-radio-group v-model="formData.IFSY" @change="IFSYChange">
                                <van-radio name="1">是</van-radio>
                                <van-radio name="2">否</van-radio>
                            </van-radio-group>
                        </div>
                    </div>
                    <van-field style="flex: 1;" v-show="formData.IFSY == '1'" v-model="formData.SYor" label="送样人"
                        placeholder="请选择送样人" readonly is-link @click="handlerSYor">
                    </van-field>
                </div>

                <div style="width: 100%;display: flex;">
                    <div class="van-cell van-field" style="flex: 1;">
                        <div class="van-cell__title van-field__label">
                            <span>是否新</span>
                        </div>
                        <div class="van-radio_group">
                            <van-radio-group v-model="formData.IFX" @change="IFXChange">
                                <van-radio name="1">是</van-radio>
                                <van-radio name="2">否</van-radio>
                            </van-radio-group>
                        </div>
                    </div>
                    <div style="flex: 1;" class="van-cell van-field" v-show='formData.IFX=="1"'>
                        <div class="van-cell__title van-field__label">
                            <span>新内容</span>
                        </div>
                        <div class="Operator" @click="handXContent">
                            <span @click='closeContent($event,index)' class="van-tag van-tag--info"
                                v-for="(item, index) in formData.XContent">
                                {{ item }}
                                <i class="van-icon van-icon-clear"></i>
                            </span>
                        </div>
                    </div>
                </div>
                <div class="bottomBtn">
                    <van-button type="info" @click="confirm('保存')">保 &nbsp &nbsp &nbsp &nbsp &nbsp 存
                    </van-button>
                    <van-button type="info" @click="confirm('打印')">打 &nbsp &nbsp &nbsp &nbsp &nbsp 印
                    </van-button>
                </div>
            </div>

            <div class="indexBottom">
                汇智云创 技术支持
            </div>
        </div>



        <van-dialog v-model="passwordshow" title="请输入口令" show-cancel-button @confirm="handlerDialog"
            @cancel="passwordshow = false">
            <!--输入框-->
            <van-field v-model="message" rows="1" autosize label="口令：" type="password" placeholder="请输入口令" />
        </van-dialog>

        <van-popup v-model="dateShow" position="bottom">
            <van-datetime-picker v-model="currentDate" type="date" title="选择操作日期" @confirm="confirmDate"
                @cancel="dateShow = false"></van-datetime-picker>
        </van-popup>

        <van-action-sheet v-model="testResultShow" :actions="testResultActions" @select="onSelectTestResult">
        </van-action-sheet>

        <van-action-sheet v-model="OperatorShow" :actions="OperatorActions" @select="onSelectOperator">
        </van-action-sheet>

        <van-action-sheet v-model="CSShow" :actions="CSActions" @select="onSelectCS">
        </van-action-sheet>
        <van-action-sheet v-model="WorkShopNameShow" :actions="WorkShopNameList" @select="onSelectWorkShopName">
        </van-action-sheet>
        <van-action-sheet v-model="GBCJShow" :actions="GBCJActions" @select="onSelectGBCJ">
        </van-action-sheet>

        <van-action-sheet v-model="SYorShow" :actions="SYorActions" @select="onSelectSYor">
        </van-action-sheet>
        <van-action-sheet v-model="XContentShow" :actions="XContentlist" @select="onXContent">
        </van-action-sheet>

    </div>
</body>

<script type="text/javascript">
    var vm;
    apiready = function () {

        var demo = api.require('xGprinterTsc');

        api.addEventListener({
            name: 'selectRow'
        }, function (ret, err) {
            console.log('ret', JSON.stringify(ret))
            if (ret.value.type == '产品') {
                vm.formData.ProductName = ret.value.row.name
                vm.formData.ProductID = ret.value.row.ProductID
                vm.formData.ProductCode = ret.value.row.ProductCode
            }
        })

        vm = new Vue({
            el: '#app',
            data: {
                buttonshow: false,
                message: '',
                passwordshow: false,
                name: api.pageParam.name,
                formData: {
                    NWH: '3',
                    AssemblingID: 0,
                    ProductName: '',
                    ProductID: '',
                    ProductCode: '',
                    OperateDate: '',
                    Batch: APP.getFormatBatch(new Date()),
                    Qty: '',
                    WorkShopName: '17号车间',
                    TestResult: '',
                    up: '',
                    down: '',
                    Operator: '',
                    OperatorList: [],
                    CS: '',
                    KTN: '2',
                    shiw: '4',
                    IFSY: '2',
                    SYor: '',
                    IFDJQ: '2',
                    IFX: '2',
                    XContent: [],
                    XContentshow: false
                },
                pagewordshow: true,
                dateShow: false,
                currentDate: new Date(),
                currentDateStr: '',
                testResultShow: false,
                testResultActions: [
                    {
                        name: '合格',
                    },
                    {
                        name: '不合格',
                    },
                ],
                OperatorActions: [],
                XContentlist: [],
                OperatorShow: false,
                CSActions: [],
                CSShow: false,
                WorkShopNameShow: false,
                WorkShopNameList: [
                    {
                        name: '17号车间',
                    },
                    {
                        name: '4号车间',
                    }
                ],
                GBCJActions: [],
                GBCJShow: false,
                List: [],
                CopyShow: false,
                Copy: 1,
                Deleteshow: false,
                SYorShow: false,
                SYorActions: [],
                XContentShow: false
            },
            created: function () {
                var that = this;
                that.setPrint()
                window.localStorage.setItem('pageName', JSON.stringify(that.name))

                if (api.pageParam.AssemblingID) {
                    that.buttonshow = true
                    that.CopyShow = true
                    APP.ajax('getAssemblingRecordsDetail', { AssemblingID: api.pageParam.AssemblingID }, function (res) {
                        console.log('res', JSON.stringify(res))
                        res.ds[0].OperateDate = res.ds[0].OperateDate ? res.ds[0].OperateDate.split('T')[0] : ''
                        that.formData = res.ds[0]
                        that.formData.up = res.ds[0].TBDate ? res.ds[0].TBDate.split(',')[0] : ''
                        that.formData.down = res.ds[0].TBDate ? res.ds[0].TBDate.split(',')[1] : ''
                        that.formData.KTN = res.ds[0].KTN == false ? '2' : '1'
                        that.formData.NWH = res.ds[0].NWH == '外焊' ? '5' : res.ds[0].NWH == '内焊' ? '4' : '3'
                        that.formData.Operator = res.ds[0].Operator
                        that.formData.OperatorList = res.ds[0].Operator.split(',')
                        // that.formData.OperatorList = res.ds[0].Operator.split(',')
                        that.formData.IFSY = res.ds[0].IFSY && res.ds[0].IFSY == true ? '1' : '2'
                        that.formData.IFDJQ = res.ds[0].IFSY == true ? '1' : '2'
                        that.formData.IFX = res.ds[0].IFX == true ? '1' : '2'
                        that.formData.XContent = res.ds[0].XContent ? res.ds[0].XContent.split(',') : []
                        // that.formData.IFX == res.ds[0].IFX == true ? '1' : '2'
                        that.formData.IFDJQ == res.ds[0].IFDJQ == true ? '1' : '2'
                    })
                } else {
                    that.formData.OperateDate = APP.getFormatDate(new Date()).split(' ')[0]
                    that.formData.TestResult = that.testResultActions[0].name
                }

            },
            mounted() {
                APP.setSafeTop()
                APP.keyBoardChange()
                APP.setPage()
            },
            methods: {
                handlerSYor() {
                    var that = this
                    APP.ajax('getJSRY', {}, function (res) {
                        console.log('res', JSON.stringify(res))
                        that.SYorActions = res.ds
                        that.SYorShow = true
                    })
                },
                IFXChange(val) {
                    var that = this
                    if (val == '2') {
                        that.formData.XContent = []
                        that.formData.XContentshow = false

                    } else {
                        that.formData.XContentshow = true
                    }
                },
                onSelectSYor(val) {
                    var that = this
                    that.formData.SYor = val.name
                    that.SYorShow = false
                },
                onXContent(val) {
                    var that = this;
                    if (that.formData.XContent.findIndex(item => { return item == val.name }) == -1) {
                        that.formData.XContent.push(val.name)
                        that.XContentShow = false
                    } else {
                        api.toast({
                            msg: '已选择该内容，请勿重复选择！'
                        })
                    }
                },
                IFSYChange(val) {
                    var that = this
                    if (val == '2') {
                        that.formData.SYor = ''
                    }
                },
                Delete() {
                    var that = this
                    that.passwordshow = true
                    that.Deleteshow = true
                },
                CopyAdd() {
                    var that = this
                    api.toast({
                        msg: '复制成功,请点击后进行保存'
                    })
                    that.Copy = 0
                },
                handlerDialog() {//确认or取消
                    var that = this
                    if (that.message == '') {
                        api.toast({
                            msg: '口令未输入'
                        })
                    } else {
                        var list = {
                            password: that.message
                        }

                        APP.ajax('getPassword', list, function (res) {
                            if (res.ds[0].status == 200) {
                                api.toast({
                                    msg: '密码输入正确'
                                })
                                if (that.Deleteshow) {
                                    var obj = {
                                        AssemblingID: api.pageParam.AssemblingID
                                    }
                                    that.$dialog.confirm({
                                        title: '提示',
                                        message: '确定删除吗？',
                                    })
                                        .then(() => {
                                            APP.ajax('deleteAssemblingRecord', obj, function (res) {
                                                setTimeout(() => {
                                                    api.closeWin();
                                                    api.sendEvent({
                                                        name: 'refreshAssembleFormList',
                                                    });
                                                }, 1000);

                                            })
                                        })
                                        .catch(() => {
                                            that.message = ''
                                        })
                                } else {
                                    var msg = that.formData.OperatorList.map(item => item).join(',') + ' 装配了 ' + that.formData.ProductName + ' ' + that.formData.Qty + '个'
                                    that.$dialog.confirm({
                                        title: '提示',
                                        message: msg + '确认保存吗？',
                                    }).then(() => {
                                        var obj = {
                                            AssemblingID: api.pageParam.AssemblingID,
                                            ProductID: that.formData.ProductID,
                                            OperateDate: that.formData.OperateDate,
                                            Batch: that.formData.Batch,
                                            Qty: that.formData.Qty,
                                            ProductName: that.formData.ProductName,
                                            Operator: that.formData.OperatorList.map(item => item).join(','),
                                            WorkShopName: that.formData.WorkShopName,
                                            TestResult: that.formData.TestResult,
                                            TBDate: that.formData.up + ',' + that.formData.down,
                                            CS: that.formData.CS,
                                            KTN: that.formData.KTN == '1' ? 1 : 0,
                                            GBCJ: that.formData.GBCJ,
                                            NWH: that.formData.NWH == '3' ? '' : that.formData.NWH == '4' ? '内焊' : '外焊',
                                            IFSY: that.formData.IFSY == '1' ? 1 : 0,
                                            SYor: that.formData.SYor,
                                            IFDJQ: that.formData.IFDJQ == '1' ? 1 : 0,
                                            IFX: that.formData.IFX == '1' ? 1 : 0,
                                            XContent: that.formData.XContent.map(item => item).join(','),
                                        }
                                        APP.ajax('updateAssemblingRecords', obj, function (res) {
                                            if (res.ds[0].Column1) {
                                                that.message = ''
                                                that.formData.AssemblingID = res.ds[0].Column1
                                                api.toast({
                                                    msg: '提交成功！'
                                                })
                                                setTimeout(() => {
                                                    api.sendEvent({
                                                        name: 'refreshAssembleFormList'
                                                    })
                                                })
                                            }
                                        })
                                    })
                                        .catch(() => {
                                            that.message = ''
                                        })
                                }
                            }
                            else {
                                api.toast({
                                    msg: '密码输入错误！'
                                })
                                that.message = ''
                            }

                        })
                    }
                },
                handlerOperator() {
                    var that = this
                    APP.ajax('getZPRY', {}, function (res) {
                        that.OperatorActions = res.ds
                        that.OperatorShow = true
                    })
                },
                handXContent() {
                    var that = this
                    APP.ajax('getXContent', {}, function (res) {
                        that.XContentShow = true
                        that.XContentlist = res.ds
                    })
                },
                closeTag(event, index) {
                    var that = this
                    event.stopPropagation();
                    that.formData.OperatorList.splice(index, 1)
                    that.OperatorShow = false
                },
                closeContent(event, index) {
                    var that = this
                    event.stopPropagation();
                    that.formData.XContent.splice(index, 1)
                    that.XContentShow = false
                    vm.$forceUpdate()

                },
                handlerWorkShopName() {
                    var that = this
                    that.WorkShopNameShow = true
                },
                handlerCS() {
                    var that = this
                    APP.ajax('getSCX', {}, function (res) {
                        that.CSActions = res.ds
                        that.CSShow = true
                    })
                },
                handlerDate(str) {
                    var that = this
                    that.currentDate = new Date()
                    that.currentDateStr = str
                    that.dateShow = true
                },
                onSelectOperator(val) {
                    var that = this;
                    if (that.formData.OperatorList.findIndex(item => { return item == val.name }) == -1) {
                        that.formData.OperatorList.push(val.name)
                        that.OperatorShow = false
                    } else {
                        api.toast({
                            msg: '已选择该人员，请勿重复选择！'
                        })
                    }
                },
                onSelectWorkShopName(val) {
                    var that = this
                    that.formData.WorkShopName = val.name
                    that.WorkShopNameShow = false
                },
                onSelectCS(val) {
                    var that = this
                    that.formData.CS = val.name
                    that.CSShow = false
                },
                handlerGBCJ() {
                    var that = this
                    APP.ajax('getGBCJ', {}, function (res) {

                        that.GBCJActions = res.ds
                        that.GBCJShow = true
                    })
                },
                onSelectGBCJ(val) {
                    var that = this
                    that.formData.GBCJ = val.name
                    that.GBCJShow = false
                },
                onClickLeft() {
                    var that = this
                    api.closeWin()
                },
                confirmDate() {
                    var that = this
                    if (that.currentDateStr == '操作日期') {
                        that.formData.OperateDate = APP.getFormatDate(that.currentDate).split(' ')[0]
                    } else if (that.currentDateStr == '正') {
                        that.formData.up = APP.getFormatDate(that.currentDate).split(' ')[0]
                    } else if (that.currentDateStr == '负') {
                        that.formData.down = APP.getFormatDate(that.currentDate).split(' ')[0]
                    }
                    that.dateShow = false
                },
                onSelectTestResult(val) {
                    var that = this
                    that.formData.TestResult = val.name
                    that.testResultShow = false
                },
                confirm(str) {
                    var that = this
                    if (api.pageParam.AssemblingID) {
                        if (that.Copy == 0) {
                            var msg = that.formData.OperatorList + ' 装配了 ' + that.formData.ProductName + ' ' + that.formData.Qty + '个'
                            that.$dialog.confirm({
                                title: '提示',
                                message: msg + '确认保存吗？',
                            }).then(() => {
                                var obj = {
                                    AssemblingID: 0,
                                    ProductID: that.formData.ProductID,
                                    OperateDate: that.formData.OperateDate,
                                    Batch: that.formData.Batch,
                                    Qty: that.formData.Qty,
                                    ProductName: that.formData.ProductName,
                                    Operator: that.formData.OperatorList.map(item => item).join(','),
                                    WorkShopName: that.formData.WorkShopName,
                                    TestResult: that.formData.TestResult,
                                    TBDate: that.formData.up + ',' + that.formData.down,
                                    CS: that.formData.CS,
                                    KTN: that.formData.KTN == '1' ? 1 : 0,
                                    GBCJ: that.formData.GBCJ,
                                    NWH: that.formData.NWH == '3' ? '' : that.formData.NWH == '4' ? '内焊' : '外焊',
                                    IFSY: that.formData.IFSY == '1' ? 1 : 0,
                                    SYor: that.formData.SYor,
                                    IFDJQ: that.formData.IFDJQ == '1' ? 1 : 0,
                                    IFX: that.formData.IFX == '1' ? 1 : 0,
                                    XContent: that.formData.XContent.map(item => item).join(','),
                                }
                                APP.ajax('updateAssemblingRecords', obj, function (res) {
                                    if (res.ds[0].Column1) {
                                        that.formData.AssemblingID = res.ds[0].Column1
                                        api.toast({
                                            msg: '提交成功！'
                                        })
                                        setTimeout(() => {
                                            api.sendEvent({
                                                name: 'refreshAssembleFormList'
                                            })
                                            if (str == '打印') {
                                                that.printLabel(that.formData.AssemblingID)
                                            }
                                        }, 500)

                                    }
                                })

                            }).catch(() => {

                            })
                            that.passwordshow = false
                        } else {
                            that.passwordshow = true
                        }
                    } else {
                        that.passwordshow = false
                        var msg = that.formData.OperatorList.map(item => item).join(',') + ' 装配了 ' + that.formData.ProductName + ' ' + that.formData.Qty + '个'
                        that.$dialog.confirm({
                            title: '提示',
                            message: msg + '确认保存吗？',
                        }).then(() => {
                            var obj = {
                                AssemblingID: that.formData.AssemblingID,
                                ProductID: that.formData.ProductID,
                                OperateDate: that.formData.OperateDate,
                                Batch: that.formData.Batch,
                                Qty: that.formData.Qty,
                                ProductName: that.formData.ProductName,
                                Operator: that.formData.OperatorList.map(item => item).join(','),
                                WorkShopName: that.formData.WorkShopName,
                                TestResult: that.formData.TestResult,
                                TBDate: that.formData.up + ',' + that.formData.down,
                                CS: that.formData.CS,
                                KTN: that.formData.KTN == '1' ? 1 : 0,
                                GBCJ: that.formData.GBCJ,
                                NWH: that.formData.NWH == '3' ? '' : that.formData.NWH == '4' ? '内焊' : '外焊',
                                IFSY: that.formData.IFSY == '1' ? 1 : 0,
                                SYor: that.formData.SYor,
                                IFDJQ: that.formData.IFDJQ == '1' ? 1 : 0,
                                IFX: that.formData.IFX == '1' ? 1 : 0,
                                XContent: that.formData.XContent.map(item => item).join(','),
                            }
                            // api.toast({
                            //     msg: obj
                            // })

                            APP.ajax('updateAssemblingRecords', obj, function (res) {
                                if (res.ds[0].Column1) {
                                    that.formData.AssemblingID = res.ds[0].Column1
                                    api.toast({
                                        msg: '提交成功！'
                                    })
                                    setTimeout(() => {
                                        api.sendEvent({
                                            name: 'refreshAssembleFormList'
                                        })
                                        if (str == '打印') {
                                            that.printLabel(that.formData.AssemblingID)
                                        }
                                    }, 500)

                                }
                            })

                        }).catch(() => {
                        })
                    }
                },


                openBaseScreen: function (str) {
                    var that = this;
                    var obj;
                    if (str == '产品') {
                        obj = {
                            allowClear: false,
                            showSearch: true,
                            searchKey: '',
                            serverSearch: false,
                            searchBy: ['name'],
                            isPaging: false,
                            type: str,
                            cmd: 'getProductList',
                            param: {}
                        }
                    }
                    api.openWin({
                        name: 'baseScreen',
                        url: 'tool/baseScreen.html',
                        reload: true,
                        slidBackEnabled: false,
                        pageParam: obj
                    })
                },
                setPrint() {
                    var that = this
                    demo.getUsbDeviceList(function (ret, err) {
                        // alert(JSON.stringify(ret));
                        if (!err) {
                            if (ret.data.length) {
                                that.connectUSB(ret.data[0].deviceName)
                            } else {
                                api.confirm({
                                    title: '提示',
                                    msg: '是否确认取消连接打印机',
                                    buttons: ['确定', '取消']
                                }, function (ret, err) {
                                    var index = ret.buttonIndex;
                                    if (ret.buttonIndex != 1) {
                                        that.setPrint()
                                    }
                                });
                            }
                        } else {
                            api.confirm({
                                title: '提示',
                                msg: '是否确认取消连接打印机',
                                buttons: ['确定', '取消']
                            }, function (ret, err) {
                                var index = ret.buttonIndex;
                                if (ret.buttonIndex != 1) {
                                    that.setPrint()
                                }
                            });
                        }
                    })
                },
                connectUSB(deviceName) {
                    var that = this
                    demo.connectUsb({
                        deviceName: deviceName
                    }, function (ret, err) {
                        if (!err) {
                            if (ret.evenType == 'onSuccess') {
                                api.toast({
                                    msg: deviceName + '打印机连接成功!',
                                    duration: 2000,
                                    location: 'bottom'
                                });
                            }
                        } else {
                            api.alert({
                                title: '打印机USB连接报错!',
                                msg: JSON.stringify(err),
                            }, function (alertRet, alerterr) {
                                if (alertRet) {
                                    that.setPrint()
                                }
                            });
                        }
                    })
                },
                printLabel() {
                    try {
                        var that = this
                        var obj = {
                            WorkShopName: that.formData.KTN == '1' ? '湿荷电池追溯单' : that.formData.WorkShopName + ' 追溯单',
                            AssemblingID: that.formData.AssemblingID ? 'ZP|' + that.formData.AssemblingID : '',
                            ProductName: that.formData.ProductName ? '产品名称: ' + that.formData.ProductName : '产品名称:',
                            OperateDate: that.formData.OperateDate ? '组装日期: ' + that.formData.OperateDate : '组装日期:',
                            up: that.formData.up ? '涂板时间:正:' + that.formData.up : '涂板时间:正: ',
                            down: that.formData.down ? '负:' + that.formData.down : '负:',
                            UserName: that.formData.OperatorList.length ? '操作者  :' + that.formData.OperatorList.join(',') : '操作者:',
                            Qty: that.formData.Qty ? '数量    :' + that.formData.Qty + '【只】' : '数量:',
                            TestResult: that.formData.TestResult ? '检验结论:' + that.formData.TestResult : '检验结论:',
                            GBCJ: that.formData.GBCJ ? '隔板厂家:' + that.formData.GBCJ : '隔板厂家:',
                            han: that.formData.NWH == '3' ? '' : that.formData.NWH == '4' ? '内焊' : '外焊',
                            KTN: that.formData.KTN == '1' ? '卡塔纳' : '',
                            CS: that.formData.CS ? '产线:' + that.formData.CS : '产线:',
                            SYor: that.formData.SYor ? '送样人：' + that.formData.SYor : '',
                            IFDJQ: that.formData.IFDJQ == '1' ? '电解铅' : '',
                            XContent: that.formData.XContent.length ? '新 :' + that.formData.XContent.join(',') : ''
                        }
                        var list = {
                            xStart: obj.WorkShopName == '湿荷电池追溯单' ? 300 : 0,
                            yStart: obj.WorkShopName == '湿荷电池追溯单' ? 160 : 0,
                            xWidth: obj.WorkShopName == '湿荷电池追溯单' ? 200 : 0,
                            yHeight: obj.WorkShopName == '湿荷电池追溯单' ? 50 : 0,
                        }
                        var a = that.formData.SYor ? true : false
                        var b = that.formData.XContent.length ? true : false
                        var listtow = {
                            Qtyy: 0,
                            GBCJy: 0,
                            UserNamey: 0,
                            TestResulty: 0,
                        }
                        if (a == false && b == false) {
                            listtow = {
                                Qtyy: 410,
                                GBCJy: 410,
                                UserNamey: 470,
                                TestResulty: 530,
                            }
                        }
                        else {
                            listtow = {
                                Qtyy: 470,
                                GBCJy: 470,
                                UserNamey: 530,
                                TestResulty: 590,
                            }
                        }
                        demo.printTsc({
                            rows: [
                                { lineType: 'size', width: 100, height: 80.4 },
                                { lineType: 'gap', m: 2, n: 0 },
                                { lineType: 'reference', x: 0, y: 0 },
                                { lineType: 'tear', data: 'true' },
                                { lineType: 'addQueryPrinterStatus', status: 'ON' },
                                { lineType: 'cls' },
                                {
                                    lineType: 'addPeel',//设置打印机剥离模式
                                    tear: 'ON'// ON/OFF 是否开启
                                },
                                {//卡塔纳
                                    lineType: 'text',
                                    x: 400,
                                    y: 110,
                                    font: 13,
                                    rotation: 0,
                                    xScal: 5,
                                    yScal: 5,
                                    data: obj.KTN
                                },
                                {
                                    lineType: 'text',
                                    x: 490,
                                    y: 110,
                                    font: 13,
                                    rotation: 0,
                                    xScal: 2,
                                    yScal: 2,
                                    data: '控制号：Q/JY-Q8.5.6-01'
                                },
                                {
                                    lineType: 'text',
                                    x: 300,
                                    y: 48,
                                    font: 13,
                                    rotation: 0,
                                    xScal: 2,
                                    yScal: 2,
                                    data: '浙江古越电源有限公司'
                                },
                                {
                                    lineType: 'text',
                                    x: 700,
                                    y: 230,
                                    font: 13,
                                    rotation: 0,
                                    xScal: 10,
                                    yScal: 10,
                                    data: obj.han
                                },
                                {//绘制文本
                                    lineType: 'text',
                                    x: 300,
                                    y: 230,
                                    font: '13',
                                    rotation: 0,
                                    xscal: 1,
                                    yscal: 1,
                                    data: obj.ProductName
                                },
                                {//绘制文本
                                    lineType: 'text',
                                    x: 600,
                                    y: 230,
                                    font: '13',
                                    rotation: 0,
                                    xscal: 1,
                                    yscal: 1,
                                    data: obj.IFDJQ
                                },
                                {
                                    lineType: 'text',
                                    x: 300,
                                    y: 170,
                                    font: 13,
                                    rotation: 0,
                                    xScal: 1,
                                    yScal: 1,
                                    data: obj.WorkShopName
                                },
                                {
                                    lineType: 'qrcode', //绘制qrcode,
                                    x: 60,
                                    y: 230,
                                    level: 'L',  //L|M|H|Q
                                    cellwith: 9,
                                    rotation: 0, // 0|90|180|270
                                    data: obj.AssemblingID
                                },

                                {//绘制文本
                                    lineType: 'text',
                                    x: 300,
                                    y: 290,
                                    font: 13,
                                    rotation: 0,
                                    xscal: 1,
                                    yscal: 1,
                                    data: obj.OperateDate
                                },
                                {//绘制文本
                                    lineType: 'text',
                                    x: 600,
                                    y: 290,
                                    font: 13,
                                    rotation: 0,
                                    xscal: 1,
                                    yscal: 1,
                                    data: obj.CS
                                },
                                {//绘制文本
                                    lineType: 'text',
                                    x: 300,
                                    y: 350,
                                    font: 13,
                                    rotation: 0,
                                    xscal: 1,
                                    yscal: 1,
                                    data: obj.up
                                },
                                {//绘制文本
                                    lineType: 'text',
                                    x: 600,
                                    y: 350,
                                    font: 13,
                                    rotation: 0,
                                    xscal: 1,
                                    yscal: 1,
                                    data: obj.down
                                },
                                {//绘制文本
                                    lineType: 'text',
                                    x: 300,
                                    y: 410,
                                    font: 13,
                                    rotation: 0,
                                    xscal: 1,
                                    yscal: 1,
                                    data: obj.XContent
                                },
                                {//绘制文本
                                    lineType: 'text',
                                    x: 600,
                                    y: 410,
                                    font: 13,
                                    rotation: 0,
                                    xscal: 1,
                                    yscal: 1,
                                    data: obj.SYor
                                },
                                {//绘制文本
                                    lineType: 'text',
                                    x: 300,
                                    y: listtow.Qtyy,
                                    font: 13,
                                    rotation: 0,
                                    xscal: 1,
                                    yscal: 1,
                                    data: obj.Qty
                                },
                                {//绘制文本
                                    lineType: 'text',
                                    x: 600,
                                    y: listtow.GBCJy,
                                    font: 13,
                                    rotation: 0,
                                    xscal: 1,
                                    yscal: 1,
                                    data: obj.GBCJ
                                },
                                {//绘制文本
                                    lineType: 'text',
                                    x: 300,
                                    y: listtow.UserNamey,
                                    font: 13,
                                    rotation: 0,
                                    xscal: 1,
                                    yscal: 1,
                                    data: obj.UserName
                                },
                                {//绘制文本
                                    lineType: 'text',
                                    x: 300,
                                    y: listtow.TestResulty,
                                    font: 13,
                                    rotation: 0,
                                    xscal: 1,
                                    yscal: 1,
                                    data: obj.TestResult
                                },
                                {
                                    lineType: 'addReverse',//将指定的区域反向打印（⿊⾊变成⽩⾊，⽩⾊变成⿊⾊）
                                    xStart: list.xStart,//起始横坐标
                                    yStart: list.yStart,//起始纵坐标
                                    xWidth: list.xWidth,//X坐标⽅向宽度，dot为单位
                                    yHeight: list.yHeight,//Y坐标⽅向⾼度，dot为单位
                                },

                                { lineType: 'addPrint', m: 1, n: 1 },
                                { lineType: 'queryPrinterStatus' },
                            ],
                            isQueryState: true,
                        }, function (ret, err) {
                            // alert(JSON.stringify(ret) + " " + JSON.stringify(err));
                            if (ret.status) {
                                api.toast({
                                    msg: '打印成功！'
                                })

                                api.pageParam.AssemblingID = 0
                                that.formData = {
                                    NWH: '3',
                                    AssemblingID: 0,
                                    ProductName: '',
                                    ProductID: '',
                                    ProductCode: '',
                                    OperateDate: APP.getFormatDate(new Date()).split(' ')[0],
                                    Batch: APP.getFormatBatch(new Date()),
                                    Qty: '',
                                    WorkShopName: '17号车间',
                                    TestResult: that.testResultActions[0].name,
                                    up: '',
                                    down: '',
                                    Operator: '',
                                    OperatorList: [],
                                    CS: '',
                                    KTN: '2',
                                    shiw: '4',
                                    IFSY: '2',
                                    SYor: '',
                                    IFDJQ: '2',
                                    IFX: '2',
                                    XContent: [],
                                    XContentshow: false
                                }

                            } else {
                                api.toast({
                                    msg: '打印失败，请重新打印！'
                                })
                            }
                        });


                    }
                    catch (e) {
                        api.alert({
                            title: '提示',
                            msg: '打印方法报错' + e,
                        }, function (alertRet, alerterr) {
                        });
                    }


                },
            }
        })
    };
</script>

</html>